import random from '../util/random'
import isArrayLike from '../util/isArrayLike'
import shuffle from './shuffle'

function sample(obj, n, guard) {
  if (!n || guard) {
    const samples = isArrayLike(obj) ? obj : Object.values(obj)
    return samples[random(samples.length - 1)]
  }
  return shuffle(obj, n)
}

export default sample
